<?php

namespace model\docs;

class docs
{
    private function menu(&$data,$levelName="")
    {
        $result = array();
        $result[]="<ul class='{$levelName}menu'>";
        foreach ($data as $v) {
            if (isset($v['clist']) && count($v['clist'])>0){
                $result[]="<li class='bd-toc-item' id='doc_{$v['clist'][0]['id']}'><a class='bd-toc-link' href='/docs/doc/{$v['clist'][0]['id']}'>{$v['title']}</a>";
                $result[] = $this->menu($v['clist'],'sub');
            }else{
                $result[]="<li class='bd-toc-item' id='doc_{$v['id']}'><a class='bd-toc-link' href='/docs/doc/{$v['id']}'>{$v['title']}</a>";
            }
            $result[]='</li>';
        }
        $result[]='</ul>';
        return  join('',$result);
    }

    public function getMenu()
    {
        $plan = M()->select("id,fid,title,description,color", 'docs', 'where ison=1 order by aorder desc , id asc');
        $ret=array_tree($plan, 'id', 'fid', 'clist', '0');
        return $this->menu($ret);
    }
}